package com.czh.springboot04.service.serviceimpl;

import com.czh.springboot04.entity.HeartKnowledge;
import com.czh.springboot04.mapper.HeartKnowledgeMapper;
import com.czh.springboot04.service.HeartKnowledgeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HeartKnowledgeServiceImpl implements HeartKnowledgeService {
    @Autowired
    private HeartKnowledgeMapper heartKnowledgeMapper;
    @Override
    public int addHeartKnowledge(HeartKnowledge heartKnowledge) {

        return heartKnowledgeMapper.addHeartKnowledge(heartKnowledge);
    }

    @Override
    public int deleteHeartKnowledge(int id) {
        return heartKnowledgeMapper.deleteHeartKnowledge(id);
    }

    @Override
    public int updateHeartKnowledge(HeartKnowledge heartKnowledge) {
        return heartKnowledgeMapper.updateHeartKnowledge(heartKnowledge);
    }

    @Override
    public PageInfo<HeartKnowledge> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<HeartKnowledge> heartKnowledgeList=heartKnowledgeMapper.findAll();
        PageInfo<HeartKnowledge> pageInfo=new PageInfo<>(heartKnowledgeList);
        return pageInfo;
    }

    @Override
    public PageInfo<HeartKnowledge> findByName(int pageNum, int pageSize,String name) {
        PageHelper.startPage(pageNum,pageSize);
        List<HeartKnowledge> heartKnowledgeList=heartKnowledgeMapper.findByName(name);
        PageInfo<HeartKnowledge> pageInfo=new PageInfo<>(heartKnowledgeList);
        return pageInfo;
    }
}
